package com.symria.taglib;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.jsp.JspException;

import org.apache.cxf.binding.corba.wsdl.Const;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.views.jsp.StrutsBodyTagSupport;

import com.symria.framework.util.Config;
import com.symria.framework.util.StringUtil;


public class ImageOut extends StrutsBodyTagSupport {
    private String src;
    private String defSrc;
    private String cssText;
    private String type;
    
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getSrc() {
		return src;
	}
	public void setSrc(String src) {
		this.src = src;
	}
	public String getDefSrc() {
		return defSrc;
	}
	public void setDefSrc(String defSrc) {
		this.defSrc = defSrc;
	}
	public String getCssText() {
		return cssText;
	}
	public void setCssText(String cssText) {
		this.cssText = cssText;
	}
	@Override
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}
	@Override
	public int doStartTag() throws JspException {
		
	    StringBuffer sBuf = new StringBuffer("");
	    String server=StringUtil.dealNull(Config.getValue("image.cache"));
	    if("doc".equals(type)){
	    	if(!StringUtil.isEmpty(src)){
	    		String href = src.matches("^ituns.*")||src.matches("^http.*")?src:src;
	    		sBuf.append("<a target=\"_blank\" href=\""+href+"\" style=\""+StringUtil.dealNull(cssText)+"\">"+href+"</a>");
	    	}
	    }else{
	    	if(!StringUtil.isEmpty(src)){
		    	sBuf.append("<img src=\""+src+"\" style=\""+StringUtil.dealNull(cssText)+"\">");
		    }else{
		    	sBuf.append("<img src=\""+StringUtil.dealNull(defSrc,"/images/employee.gif")+"\" style=\""+StringUtil.dealNull(cssText)+"\">");
		    }
	    }
	    try {
			pageContext.getOut().write(sBuf.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_BUFFERED;
	}
	
	
    
}
